def expand(digitlistlist, length):
    result = []
    
    for digitlist in digitlistlist:
        if length <= len(digitlist):
            result.append(digitlist)
        else:
            result += [ digitlist + [d] for d in xrange(0, 10)]
 
    return result

print expand([1,2], 4)
exit()

squares = [(0, 1), (0, 4), (0, 9), (1, 6), (2, 5), (3, 6), (4, 9), (8, 1)]
#squares = [(0, 1), (0, 4), (0, 9), (1, 6)]

combos = [ [[], []] ]

for s in squares:
    left  = [ [c[0] + [s[0]], c[1] + [s[1]]] for c in combos ]
    right = [ [c[0] + [s[1]], c[1] + [s[0]]] for c in combos ]
    combos = left + right

for c in combos:
    left = list(sorted(set(c[0])))
    if 6 < len(left): continue

    lefts = expand(left, 6)
    
    right = list(sorted(set(c[1])))
    if 6 < len(right): continue

    
    print left, right
            
    


        